import React, { useContext, useMemo } from 'react';
import { Button, Space } from 'antd';
import { WorkflowHndTaskBtn } from '@/components/WorkflowCommonCopy';
import { DocumentControllerContext } from '../common/useOAContext';
import { getPosIDs, getTenantID, getUserID } from '@/utils';
import { BZ_flowBusinessType, DBZ_STATE, WJBZZ_STATE } from '../common/Format';
import { RollbackOutlined } from '@ant-design/icons';
import { SHTH_CHECKSTATE, SHZ_CHECKSTATE } from '../../Acommon';
import moment from 'moment';
import { ILoadMapTypeAll } from '@/common';
export const DetailInfoBottomBtnView: React.FC = () => {
  /** 引入上下文 */
  const { curRes, taskId, styleFixCls, infoObj, reloadDetail, setInvalidState, setOAMessageRun } = useContext(DocumentControllerContext);

  const allBtnsMemo = useMemo(() => {
    let isShowBtn = {
      revokeBtnDiv: false, //撤销按钮
      flowHandList: {}, //流程办理数据
    };

    /** 处理流程办理数据 */
    const taskType: string = BZ_flowBusinessType();
    const taskHandInfo: Record<string, any> = infoObj?.paramObject?.[taskType];
    if (
      taskHandInfo &&
      taskHandInfo?.mactivitiTaskList?.length > 0 &&
      taskHandInfo?.mactivitiTaskList?.[0]?.assigneePositionID == getPosIDs() &&
      taskHandInfo?.mactivitiTaskList?.[0]?.assigneeID == getUserID()
    ) {
      isShowBtn['invalBoolBtn'] = true;
      isShowBtn['allBtnDiv'] = true;
      // isShowBtn['flowHandList'] = taskHandInfo?.mactivitiTaskList?.[0];
      isShowBtn['flowHandList'] = infoObj;
    }

    return isShowBtn;
  }, [infoObj]);

  return (
    <div className={`${styleFixCls}infoViewOA-bottomBtnBox-spaceItemBox`}>
      <Space>
        {/* 流程节点弹框 */}
        <WorkflowHndTaskBtn
          flowDetailInfo={infoObj}
          reloadCallback={reloadDetail}
          requestController={'purchaseSourceController'}
          clickSuccessFun={() => {
            setOAMessageRun({
              id: taskId,
              isRemark: 2,
              viewType: 1,
              endTime: moment()?.format('YYYY-MM-DD HH:mm:ss'),
            });
          }}
          flowBusinessType={BZ_flowBusinessType()}
          isAloneSubmit={infoObj?.state == WJBZZ_STATE() && infoObj?.checkState == SHTH_CHECKSTATE()}
          applyHeader={'own'}
          revokeRequestUrl={'/purchaseSourceController/invalid'}
          revokeRequestState={`${getTenantID()}${ILoadMapTypeAll?.CURRYOUT_STATE}`}
          isShowRevokeStateList={[WJBZZ_STATE()]}
          revokeTitle={infoObj?.packName}
          revokeSuccessCallback={reloadDetail}
        />
        {/* {curRes?.['/purchaseSourceController/invalid'] &&
          infoObj?.id &&
          infoObj?.ownerID == getUserID() &&
          infoObj?.ownPositionID == getPosIDs() &&
          (infoObj?.state == WJBZZ_STATE() || (infoObj?.state == DBZ_STATE() && infoObj?.checkState == SHZ_CHECKSTATE())) && (
            <Button
              type="primary"
              danger
              // icon={<RollbackOutlined />}
              onClick={() => {
                setInvalidState({ isShow: true, resObj: infoObj });
              }}
            >
              撤销
            </Button>
          )} */}
      </Space>
    </div>
  );
};
